package com.dianzhihan.cashier.mapper;

import com.dianzhihan.cashier.model.product.Product;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

@Repository
@Mapper
public interface ProductMapper {
    //商品上架
    void insert(Product product);

    //商品列表查询
    List<Product> selectAll();

    //商品更新
    void update(Product product);

    //根据商品ID来查询商品的集合
    List<Product> selectProductListByProductIdSet(@Param("list") Set<Integer> productIdSet);

    //查询是否有这个商品在商品表里面
    @Select("select count(product_id) from products where product_id = #{id}")
    int selectCountById(@Param("id") int id);

    //减少库存
    void decrementStockByProductId(@Param("productId") int productId, @Param("number") int number);
    //增加库存
    void stockIncrementByProductId(@Param("productId") int productId,@Param("number") int number);


    //根据商品ID来从商品表删除商品
    @Delete("delete from products where product_id = #{id}")
    void deleteById(@Param("id") int id);
}
